﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZX.HIS.Model;
using ZX.HIS.BLL;
using ZX.HIS.SQLServerDAL;
using ZX.HIS.OracleDAL;
using ZX.HIS.Common;
using System.Text;

namespace ZX.HIS.UI.Controllers
{
    public class MedicalItemController : Controller
    {
        ZX.HIS.BLL.MedicalItem Mbll = new BLL.MedicalItem();
        //
        // GET: /MedicalItem/
        /// <summary>
        /// 检查医疗项试图
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 检查医疗添加方法
        /// </summary>
        /// <returns></returns>
        public ActionResult MedicalItemAdd()
        {
            ZX.HIS.Model.MedicalItem med = new Model.MedicalItem();
            med.HospitalId = 1001;
            med.MedicalItemId =Convert.ToInt32( Request["MedicalItemId"]);
            med.MedicalItemName = Request["MedicalItemName"].ToString();
            med.MedicalItemCostPrice =decimal.Parse( Request["MedicalItemCostPrice"]);
            med.MedicalItemSalePrice =decimal.Parse( Request["MedicalItemSalePrice"]);
            int i = Mbll.MedicalItemAdd(med);
            if (i > 0)
            {
                return Content("<script>alert('添加成功');location.href='/MedicalItem/MedicalItemShow';</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');location.href='/MedicalItem/MedicalItemShow';</script>");
            }
        }
        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="StrOrder"></param>
        /// <param name="StrWhere"></param>
        /// <returns></returns>

        public ActionResult MedicalItemShow()
        {
            ZX.HIS.BLL.MedicalItem DIBLL = new BLL.MedicalItem();
            string name = "";
            if (!String.IsNullOrEmpty(Request["MedicalItemName"]))
            {
                name = Request["MedicalItemName"].ToString();
                Session["MedicalItemName"] = name;
            }
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            PageClass<ZX.HIS.Model.MedicalItem> pagelist =Mbll.MedicalItemShow(1, 3, name,HospitalId);
            return View(pagelist);
        }
        public ActionResult page(int id)
        {
            string name = "";
            if (Session["MedicalItemName"] != null)
            {
                name = Session["MedicalItemName"].ToString();
            }
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            PageClass<ZX.HIS.Model.MedicalItem> pagelist =Mbll.MedicalItemShow (id, 3, name,HospitalId);
            return View("MedicalItemShow", pagelist);
        }

        /// <summary>
        /// 伪删除
        /// </summary>
        /// <param name="IDS"></param>
        /// <param name="DeparStarte"></param>
        /// <returns></returns>
        public ActionResult MedicalItemDel(int id)
        {
            ZX.HIS.Model.MedicalItem mode = new Model.MedicalItem();
            mode.MedicalItemId = id;
            mode.MedicalItemState = -1;
            ZX.HIS.BLL.DepartInfo DIBLL = new BLL.DepartInfo();
            if (Mbll.MedicalItemDel(mode) > 0)
            {
                return Content("<script>alert('删除成功');location.href='/MedicalItem/MedicalItemShow';</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/MedicalItem/MedicalItemShow';</script>");
            }
        }
        /// <summary>
        /// 修改视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult MedicalItemUpd(int id)
        {
            ZX.HIS.Model.MedicalItem tt = Mbll.list().Where(p => (p.MedicalItemId == id)).FirstOrDefault();
            ViewData["MedicalItemId"] = tt;
            return View("MedicalItemUpd");
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult MedicalItemUpdmo(ZX.HIS.Model.MedicalItem model)
        {
            int i = Mbll.MedicalItemUpd(model);
            if (i > 0)
            {
                return Content("<script>alert('修改成功');location.href='/MedicalItem/MedicalItemShow';</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='/MedicalItem/MedicalItemShow';</script>");
            }
        }

    }
}
